package com.uuah.server.exception;

import java.io.PrintWriter;
import java.io.StringWriter;

import com.uuah.config.i18n.Message;
import com.uuah.exception.AbstractUuahException;
import com.uuah.server.config.i18n.ServerMessages;
import com.uuah.utils.StringUtils;
import com.uuah.utils.SystemUtils;

/**
 *
 * TODO comment ...
 *
 * <p>
 * update record:updator，update time，update content and version
 * </p>
 *
 * @author <a href="jonny_quan@hotmail.com">jonny</a>
 * @date 2009 2009-3-27 下午01:45:14
 * @version 1.0.0
 */
public class AbstractUuahServerException extends AbstractUuahException {
	/**
	 *
	 */
	private static final long serialVersionUID = -1613021200356837909L;

	public AbstractUuahServerException() {
		super();
		initialise();
	}

	public AbstractUuahServerException(Message message, Throwable cause) {
		super(message, cause);
	}

	public AbstractUuahServerException(Message message) {
		super(message);
	}

	public AbstractUuahServerException(Throwable cause) {
		super(cause);
		initialise();
	}

	public String getDetailedMessage() {
		StringBuffer buf = new StringBuffer(1024);
		buf.append(SystemUtils.LINE_SEPARATOR).append(
				StringUtils.repeat('*', 80)).append(SystemUtils.LINE_SEPARATOR);
		buf.append("Message               : ").append(message).append(
				SystemUtils.LINE_SEPARATOR);
		buf.append("Type                  : ").append(getClass().getName())
				.append(SystemUtils.LINE_SEPARATOR);
		buf.append("Code                  : ").append("UUAH_ERROR-").append(
				getMessageCode()).append(SystemUtils.LINE_SEPARATOR);

		buf.append(StringUtils.repeat('*', 80)).append(
				SystemUtils.LINE_SEPARATOR);
		buf.append(ServerMessages.exceptionStackIs()).append(
				SystemUtils.LINE_SEPARATOR);

		buf.append(StringUtils.repeat('*', 80)).append(
				SystemUtils.LINE_SEPARATOR);
		buf.append(ServerMessages.rootStackTrace()).append(
				SystemUtils.LINE_SEPARATOR);
		StringWriter w = new StringWriter();
		PrintWriter p = new PrintWriter(w);
		this.printStackTrace(p);
		buf.append(w.toString()).append(SystemUtils.LINE_SEPARATOR);
		buf.append(StringUtils.repeat('*', 80)).append(
				SystemUtils.LINE_SEPARATOR);

		return buf.toString();
	}
}
